package cn.com.headfree.workflow.service.impl;

import cn.com.headfree.entity.*;
import cn.com.headfree.entity.isc.User;
import cn.com.headfree.userinfo.dao.IUserInfoDao;
import cn.com.headfree.vo.workflow.DbCount;
import cn.com.headfree.vo.workflow.ProcessListVo;
import cn.com.headfree.workflow.dao.IWorkFlowProcessDao;
import cn.com.headfree.workflow.service.IWorkFlowProcessService;
import com.gta.edu.sdk.common.dto.Page;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @program: human-manage-parent
 * @description: 流程查询ServiceImpl
 * @author: panl
 * @create: 2020-07-03 16:32
 **/
@Service
public class WorkFlowProcessServiceImpl implements IWorkFlowProcessService {
    @Autowired
    public IWorkFlowProcessDao iWorkFlowProcessDao;
    @Autowired
    public IUserInfoDao iUserInfoDao;

    @Override
    public void queryProcess(ProcessListVo processListVo,Page<ProcessListVo>page,User user) {
        //根据信息类别ID查询需要关联的表
        String tableName= "";
        String businessTypeName = "";
        TMouldInfo tMouldInfo = new TMouldInfo();
        tMouldInfo.setId(processListVo.getBusinessTypeId());
        List<TMouldInfo> mouldInfoList = iUserInfoDao.getMouldInfoList(tMouldInfo);
        if(mouldInfoList!=null && mouldInfoList.size()>0){
            tableName = mouldInfoList.get(0).getTabName();
            businessTypeName = mouldInfoList.get(0).getMouldName();
        }
        if(!StringUtils.isEmpty(tableName)){
            processListVo.setTabName(tableName);
        }
        iWorkFlowProcessDao.queryProcess(processListVo,page,user);
    }

    @Override
    public int deleteProcess(ProcessListVo processListVo) throws Exception{
        String tableName= "";
        TMouldInfo tMouldInfo = new TMouldInfo();
        tMouldInfo.setId(processListVo.getBusinessTypeId());
        List<TMouldInfo> mouldInfoList = iUserInfoDao.getMouldInfoList(tMouldInfo);
        if(mouldInfoList!=null && mouldInfoList.size()>0){
            tableName = mouldInfoList.get(0).getTabName();
        }
        if(!StringUtils.isEmpty(tableName)){
            processListVo.setTabName(tableName);
        }
        return iWorkFlowProcessDao.deleteProcess(processListVo);
    }

    @Override
    public int updateTWorkExpInfo(TWorkExpInfo tWorkExpInfo, User user) throws Exception {
        if(user!=null){
            tWorkExpInfo.setUpdaterId(user.getFax());
            tWorkExpInfo.setUpdaterName(user.getName());
        }
        return iWorkFlowProcessDao.updateTWorkExpInfo(tWorkExpInfo);
    }

    @Override
    public int updateTSdtTutorPrentInfo(TSdtTutorPrentInfo tSdtTutorPrentInfo, User user) throws Exception {
        if(user!=null){
            tSdtTutorPrentInfo.setUpdaterId(user.getFax());
            tSdtTutorPrentInfo.setUpdaterName(user.getName());
        }
        return iWorkFlowProcessDao.updateTSdtTutorPrentInfo(tSdtTutorPrentInfo);
    }

    @Override
    public int updateTProjAchieveInfo(TProjAchieveInfo tProjAchieveInfoVo, User user) throws Exception {
        if(user!=null){
            tProjAchieveInfoVo.setUpdaterId(user.getFax());
            tProjAchieveInfoVo.setUpdaterName(user.getName());
        }
        return iWorkFlowProcessDao.updateTProjAchieveInfo(tProjAchieveInfoVo);
    }

    @Override
    public int updateTHonorInfo(THonorInfo tHonorInfo, User user) throws Exception {
        if(user!=null){
            tHonorInfo.setUpdaterId(user.getFax());
            tHonorInfo.setUpdaterName(user.getName());
        }
        return iWorkFlowProcessDao.updateTHonorInfo(tHonorInfo);
    }

    @Override
    public int updateTTecManInnov(TTecManInnov tTecManInnov, User user) throws Exception {
        if(user!=null){
            tTecManInnov.setUpdaterId(user.getFax());
            tTecManInnov.setUpdaterName(user.getName());
        }
        return iWorkFlowProcessDao.updateTTecManInnov(tTecManInnov);
    }

    @Override
    public int updateTContestInfo(TContestInfo tContestInfo, User user) throws Exception {
        if(user!=null){
            tContestInfo.setUpdaterId(user.getFax());
            tContestInfo.setUpdaterName(user.getName());
        }
        return iWorkFlowProcessDao.updateTContestInfo(tContestInfo);
    }

    @Override
    public int updateTTecInnovInfo(TTecInnovInfo tTecInnovInfo, User user) throws Exception {
        if(user!=null){
            tTecInnovInfo.setUpdaterId(user.getFax());
            tTecInnovInfo.setUpdaterName(user.getName());
        }
        return iWorkFlowProcessDao.updateTTecInnovInfo(tTecInnovInfo);
    }

    @Override
    public int updateTPatentInfo(TPatentInfo tPatentInfo, User user) throws Exception {
        if(user!=null){
            tPatentInfo.setUpdaterId(user.getFax());
            tPatentInfo.setUpdaterName(user.getName());
        }
        return iWorkFlowProcessDao.updateTPatentInfo(tPatentInfo);
    }

    @Override
    public int updateTStandInfo(TStandInfo tStandInfo, User user) throws Exception {
        if(user!=null){
            tStandInfo.setUpdaterId(user.getFax());
            tStandInfo.setUpdaterName(user.getName());
        }
        return iWorkFlowProcessDao.updateTStandInfo(tStandInfo);
    }

    @Override
    public int updateTAcadeAchiveInfo(TAcadeAchiveInfo tAcadeAchiveInfo, User user) throws Exception {
        if(user!=null){
            tAcadeAchiveInfo.setUpdaterId(user.getFax());
            tAcadeAchiveInfo.setUpdaterName(user.getName());
        }
        return iWorkFlowProcessDao.updateTAcadeAchiveInfo(tAcadeAchiveInfo);
    }

    @Override
    public int updateTExpertTitleInfo(TExpertTitleInfo tExpertTitleInfo, User user) throws Exception {
        if(user!=null){
            tExpertTitleInfo.setUpdaterId(user.getFax());
            tExpertTitleInfo.setUpdaterName(user.getName());
        }
        return iWorkFlowProcessDao.updateTExpertTitleInfo(tExpertTitleInfo);
    }

    @Override
    public int updateTSkillLevelInfo(TSkillLevelInfo tSkillLevelInfo, User user) throws Exception {
        if(user!=null){
            tSkillLevelInfo.setUpdaterId(user.getFax());
            tSkillLevelInfo.setUpdaterName(user.getName());
        }
        return iWorkFlowProcessDao.updateTSkillLevelInfo(tSkillLevelInfo);
    }

    @Override
    public int updateTProTecInfo(TProTecInfo tProTecInfo, User user) throws Exception {
        if(user!=null){
            tProTecInfo.setUpdaterId(user.getFax());
            tProTecInfo.setUpdaterName(user.getName());
        }
        return iWorkFlowProcessDao.updateTProTecInfo(tProTecInfo);
    }

    @Override
    public int updateTContiStudyInfo(TContiStudyInfo tContiStudyInfo, User user) throws Exception {
        if(user!=null){
            tContiStudyInfo.setUpdaterId(user.getFax());
            tContiStudyInfo.setUpdaterName(user.getName());
        }
        return iWorkFlowProcessDao.updateTContiStudyInfo(tContiStudyInfo);
    }
    /**
	 * 挂职轮岗
	 * @author yangwang
	 * @param tRotationInfo
	 * @param user
	 * @return int
	 *  */
    @Override
    public int updateTRotationInfo(TRotationInfo tRotationInfo,User user) throws Exception{
    	if(user!=null){
    		tRotationInfo.setUpdaterId(user.getFax());
    		tRotationInfo.setUpdaterName(user.getName());
        }
        return iWorkFlowProcessDao.updateTRotationInfo(tRotationInfo);
    }

	@Override
	public List<DbCount> queryBusinessTypeLsit(User user) {
		// TODO Auto-generated method stub
		return iWorkFlowProcessDao.queryBusinessTypeLsit(user);
	}

	@Override
	public int updateTEmployeeMobility(TEmployeeMobility employeeMobility, User user) {
		if(user!=null){
			employeeMobility.setUpdaterId(user.getFax());
			employeeMobility.setUpdaterName(user.getName());
        }
        return iWorkFlowProcessDao.updateTEmployeeMobility(employeeMobility);
	}

    @Override
    public int updateTecStandardInfo(TTecStandardInfo tecStandardInfo,User user)throws Exception{
        if(user!=null){
            tecStandardInfo.setUpdaterId(user.getFax());
            tecStandardInfo.setUpdaterName(user.getName());
        }
        return iWorkFlowProcessDao.updateTecStandardInfo(tecStandardInfo);
    }
}
